<!-- 简历页 -->
<template>
  <div>
    <VitaeList
        @delVitae="delVitae"
        @updateVitae="updateVitae"
        :vitaeData="vitaeData"
    >
    </VitaeList>
    <div class="submit">
      <el-button
          @click="addVitae"
          type="primary"
          round size="large">新建简历</el-button>
    </div>
  </div>
</template>
<script setup>
import { inject, watch , ref} from 'vue';
import { useRouter } from 'vue-router'
import checkLoginStatus from '@/hooks/checkLoginStatus.js'
import login from '@/hooks/login.js'
import VitaeList from '@/components/vitaeList.vue'
const $axios = inject('$axios')
const $root = inject('$root')
const router = useRouter()
let vitaeData = ref([])

// 获取简历列表
const getVitaeData = () => {
  $axios.get($root+`/curri/`).then(r=>{
    vitaeData.value = r.data.data
  })
}

//编辑简历
const updateVitae = (cid)=>{
  router.push(`/addvitae/${cid}`)
}

//删除简历
const delVitae = (cid)=>{
  $axios.post($root+`/curri/delete/${cid}/`).then(r=>{
    if(r.data.code == 200){
      getVitaeData()
    }
  })
}

//添加简历
const addVitae = ()=>{
  router.push('/addvitae')
}

watch(() => router.currentRoute.value.name, (name) => {
  if (name == "vitae") {
    checkLoginStatus(getVitaeData, login)
  }
}, { immediate: true, deep: true })

</script>